package com.qijin.util;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;


@Slf4j
public class IdWorker {
    private static long workerId;//为终端ID
    private static final long datacenterId = 1;//数据中心ID
    private static final Snowflake snowflake = IdUtil.createSnowflake(workerId, datacenterId);

    static {
        workerId = NetUtil.ipv4ToLong(NetUtil.getLocalhostStr());
        log.info("当前机器的workId:{}", workerId);
    }

    public synchronized static long getId() {
        return snowflake.nextId();
    }

}
